package com.ruoyi.employer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.employer.domain.CargoMoney;
import com.ruoyi.employer.service.ICargoMoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 货主端兑换中心Controller
 * 
 * @author fxy
 * @date 2024-08-23
 */
@RestController
@RequestMapping("/employer/carGoMoney")
public class CargoMoneyController extends BaseController
{
    @Autowired
    private ICargoMoneyService cargoMoneyService;

    /**
     * 查询货主端兑换中心列表
     */
    @PreAuthorize("@ss.hasPermi('employer:carGoMoney:list')")
    @GetMapping("/list")
    public TableDataInfo list(CargoMoney cargoMoney)
    {
        startPage();
        List<CargoMoney> list = cargoMoneyService.selectCargoMoneyList(cargoMoney);
        return getDataTable(list);
    }

    /**
     * 导出货主端兑换中心列表
     */
    @PreAuthorize("@ss.hasPermi('employer:carGoMoney:export')")
    @Log(title = "货主端兑换中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CargoMoney cargoMoney)
    {
        List<CargoMoney> list = cargoMoneyService.selectCargoMoneyList(cargoMoney);
        ExcelUtil<CargoMoney> util = new ExcelUtil<CargoMoney>(CargoMoney.class);
        util.exportExcel(response, list, "货主端兑换中心数据");
    }

    /**
     * 获取货主端兑换中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('employer:carGoMoney:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cargoMoneyService.selectCargoMoneyById(id));
    }

    /**
     * 新增货主端兑换中心
     */
    @PreAuthorize("@ss.hasPermi('employer:carGoMoney:add')")
    @Log(title = "货主端兑换中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CargoMoney cargoMoney)
    {
        return toAjax(cargoMoneyService.insertCargoMoney(cargoMoney));
    }

    /**
     * 修改货主端兑换中心
     */
    @PreAuthorize("@ss.hasPermi('employer:carGoMoney:edit')")
    @Log(title = "货主端兑换中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CargoMoney cargoMoney)
    {
        return toAjax(cargoMoneyService.updateCargoMoney(cargoMoney));
    }

    /**
     * 删除货主端兑换中心
     */
    @PreAuthorize("@ss.hasPermi('employer:carGoMoney:remove')")
    @Log(title = "货主端兑换中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cargoMoneyService.deleteCargoMoneyByIds(ids));
    }
}
